import { Injectable } from '@angular/core';
import { Router } from '@angular/router';
import { HttpRequest } from "../../service/httpRequest";

@Injectable()
export class RepairService {

  orderId:string = '';
  username:string = '';
  constructor(
    private httpRequest:HttpRequest,
    private _router: Router){
    this.username = JSON.parse(localStorage.getItem('account'))['username'];
  }

  getData():any{
    return this.httpRequest.sendGet('guzhang/detail',{
        id:this.orderId
    });
  }

  getDetailData():any{
    return this.httpRequest.sendGet('guzhang/chakan',{
      id:this.orderId
    });
  }

  getAllItems():any{
    return this.httpRequest.sendGet('guzhang/onlines',{
      id:this.orderId
    });
  }

  getServiceMan():any{
    return this.httpRequest.sendGet('account/serviceman');
  }

  save(type,params):any{
    let action = '';
    switch (type){
      case 'receive':
        action = 'guzhang/jiejing';
        break;
      case 'confirm':
        action = 'guzhang/khqr';
        break;
      case 'complete':
        action = 'guzhang/wangong';
        break;
      case 'revoke':
        action = 'guzhang/chexiao';
        break;
      default:
        alert('请确认类型');
        return;
    }

    return this.httpRequest.sendPost(action,params);
  }

  getTime(){
    return this.httpRequest.gettoday();
  }

  cancel(url = ''){
    if(url == '') url = 'order';

    this._router.navigateByUrl('page/repair/'+url);
  }
}
